package com.sixbro.common.domain;

/**
 * <p>
 *
 * </p>
 *
 * @author: Mr.Lu
 * @since: 2021/6/15 17:36
 */
public enum ApiResponseCode implements IResponseCode {
    SUCCESS("00000", "一切ok"),
    FAILURE("A0000", "业务异常"),
    USER_ERROR("A0001", "用户端错误"),
    USER_LOGIN_ERROR("A0200", "用户登录异常"),
    USER_NOT_EXIST("A0201", "用户不存在"),
    USER_ACCOUNT_LOCKED("A0202", "用户账户被冻结"),
    USER_ACCOUNT_INVALID("A0203", "用户账户已作废"),
    USERNAME_OR_PASSWORD_ERROR("A0210", "用户名或密码错误"),
    INPUT_PASSWORD_EXCEED_LIMIT("A0211", "用户输入密码次数超限"),
    CLIENT_AUTHENTICATION_FAILED("A0212", "客户端认证失败"),
    TOKEN_INVALID_OR_EXPIRED("A0230", "token无效或已过期"),
    TOKEN_ACCESS_FORBIDDEN("A0231", "token已被禁止访问"),
    AUTHORIZED_ERROR("A0300", "访问权限异常"),
    ACCESS_UNAUTHORIZED("A0301", "访问未授权"),
    FORBIDDEN_OPERATION("A0302", "演示环境禁止修改、删除重要数据，请本地部署后测试"),
    PARAM_ERROR("A0400", "用户请求参数错误"),
    PARAM_IS_NULL("A0410", "请求必填参数为空"),
    QUERY_MODE_IS_NULL("A0411", "查询模式为空"),
    USER_UPLOAD_FILE_ERROR("A0700", "用户上传文件异常"),
    USER_UPLOAD_FILE_TYPE_NOT_MATCH("A0701", "用户上传文件类型不匹配"),
    USER_UPLOAD_FILE_SIZE_EXCEEDS("A0702", "用户上传文件太大"),
    USER_UPLOAD_IMAGE_SIZE_EXCEEDS("A0703", "用户上传图片太大"),
    SYSTEM_EXECUTION_ERROR("B0001", "系统执行出错"),
    SYSTEM_EXECUTION_TIMEOUT("B0100", "系统执行超时"),
    SYSTEM_ORDER_PROCESSING_TIMEOUT("B0100", "系统订单处理超时"),
    ;

    /**
     * 状态码
     */
    private String code;
    /**
     * 消息内容
     */
    private String message;

    ApiResponseCode(final String code, final String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return String.format(" ErrorCode:{code=%s, msg=%s} ", this.code, this.message);
    }

    public static ApiResponseCode resolve(String code){
        for (ApiResponseCode apiResponseCode : values()) {
            if (apiResponseCode.code.equals(code)) {
                return apiResponseCode;
            }
        }
        // 默认系统执行错误
        return null;
    }
}
